package com.xxx.mch.controller;

import com.xxx.mch.domain.po.SystemConfig;
import com.xxx.mch.service.SystemConfigService;
import com.xxx.mch.utils.WrapMapper;
import com.xxx.mch.utils.Wrapper;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author FengHaixin
 * @description 一句话描述该文件的用途
 * @date 2020/3/1
 */
@RestController
@RequestMapping ("config")
public class ConfigController
{
    @Autowired
    private SystemConfigService systemConfigService;


    /**
     * 获取积分配置合权重配置
     *
     * @param type String：weight和points
     */
    @ApiOperation (value = "权重设置界面查询配置")
    @GetMapping (value = "{type}", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "type", required = true,value = "type可取值：points表示积分配置leaderWeight表示4大领导权重；scoreWeight定性和定量分权重")
    public Wrapper<List<SystemConfig>> getConfig(@PathVariable ("type") String type)
    {
        return WrapMapper.ok(systemConfigService.queryConfigByType(type));
    }


    @ApiOperation (value = "权重和积分配置更新接口")
    @PostMapping (produces = MediaType.APPLICATION_JSON_VALUE)
    public Wrapper<String> updateConfig(@RequestBody List<SystemConfig> systemConfigList)
    {
        systemConfigService.updateConfig(systemConfigList);
        return WrapMapper.ok();
    }
}
